<?php

abstract class Rule {

    protected $Type;
    protected $Value;
    protected $FieldName;

    const REQUIRED = 'Required';
    const NUMERIC = 'numeric';
    const LENGHT = 'Length';
    const TYPE = 'Type';
    const MATCH = 'match';

    public function __construct($Type, $Value, $FieldName) {
        $this->Type = $Type;
        $this->Value = $Value;
        $this->FieldName = $FieldName;
    }

    public static function create($Type, $Value, $FieldName) {
        $Rules = array(
            Rule::REQUIRED => new RequiredRule($Type, $Value, $FieldName),
            Rule::NUMERIC => new NumericRule($Type, $Value, $FieldName),
            Rule::LENGHT => new LenghtRule($Type, $Value, $FieldName),
            Rule::TYPE => new TypeRule($Type, $Value, $FieldName),
            Rule::MATCH => new MatchRule($Type, $Value, $FieldName)
        );

        return $Rules[$Type];
    }

    public abstract function validate($ValueToValidate);

    public abstract function getMessage();
}

?>
